package com.sangmo.fts.process.storage.service;

import com.sangmo.boot.framework.plugin.dataview.crud.service.BaseViewService;
import com.sangmo.boot.framework.plugin.dataview.data.IDataViewRepo;
import com.sangmo.fts.common.authority.service.AuthorityEntityService;
import com.sangmo.fts.process.storage.interfaces.CsfInboundCreation;
import com.sangmo.fts.process.storage.model.CsfInbound;
import com.sangmo.fts.process.storage.model.CsfOutbound;
import com.sangmo.fts.process.storage.repo.CsfInboundRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class CsfInboundEntityService extends AuthorityEntityService<CsfInbound> {

    @Autowired
    private CsfInboundRepo csfInboundRepo;

    @Autowired
    private CsfOutboundService csfOutboundService;

    @Override
    protected IDataViewRepo<CsfInbound> getRepo() {
        return csfInboundRepo;
    }

    @Override
    protected void onCreate(CsfInbound entity, Object bo) {
        super.onCreate(entity, bo);
        CsfInboundCreation creation = (CsfInboundCreation) bo;
        CsfOutbound outbound = csfOutboundService.get(creation.getOutboundId());
        entity.setBillId(outbound.getBillId());
        entity.setLoanId(outbound.getLoanId());
        entity.setContractId(outbound.getContractId());
        entity.setShipper(outbound.getShipper());
        entity.setConsignee(outbound.getConsignee());
    }
}
